package testSudoku;

import static org.junit.Assert.*;
import sudoku.*;
import junit.framework.TestCase;
import org.junit.Before;
import org.junit.Test;

public class testValidator
{

		private Validator validator;
		/**
		 * Sets up the test fixture.
		 * Called before every test case method.
		 */
		@Before
		public void setUp() 
		{ 
			validator =new Validator();	
		}
		/**
		 * Tears down the test fixture.
		 * Called after every test case method.
		 */
		public void tearDown() {}
		
		
		// Test case 1: test class "validator": Players cannot change default number in question
		// Ques_arr[1][1] = '1' but users enter a number in the box
		@Test
		public void testChangeDefaultNum() 
		{
			boolean result;
			int x = 1;
			int y = 1;
			char[][] Ques_arr = new char[9][9];
			Ques_arr[1][1] = '1';
			char[][] Bd_arr = new char[9][9];
		
			String input = "1";
			char i = 1;
			result = validator.check_input(Ques_arr, Bd_arr, x , y ,input, i,0);
			assertEquals(result, false);
		}
		
		
		// Test case 2: test class "validator": Players cannot insert repeat number in other column or row
		//Bd_arr[1][2] = i ,but users want to enter "i" in Bd_arr[1][1] 
		@Test
		public void testInsertRepeatNum() 
		{
			boolean result;
			int x = 1;
			int y = 1;
			char[][] Ques_arr = new char[9][9];
			char[][] Bd_arr = new char[9][9];
			String input = "1";
			char i = 1;
			Bd_arr[1][2] = i;
		
		
			result = validator.check_input(Ques_arr, Bd_arr, x , y ,input, i,0);
			assertEquals(result, false);
		}
		
		
		
		
		
		
		// Test case 3: test class "validator": x coordinate can't less than 0
		@Test
		public void testXnotLess0() 
		{
			boolean result;
			int x = -2;
			int y = 1;
			char[][] Ques_arr = new char[9][9];
			char[][] Bd_arr = new char[9][9];
		
			String input = "1";
			char i = 1;
			result = validator.check_input(Ques_arr, Bd_arr, x , y ,input, i,0);
			assertEquals(result, false);
		}
		
		// Test case 4: test class "validator": X coordinate can't larger than 8
		@Test
		public void testXnotLarger8() 
		{
			boolean result;
			int x = 9;
			int y = 1;
			char[][] Ques_arr = new char[9][9];
			char[][] Bd_arr = new char[9][9];
		
			String input = "1";
			char i = 1;
			result = validator.check_input(Ques_arr, Bd_arr, x , y ,input, i,0);
			assertEquals(result, false);
		}
		
		
		// Test case 5: test class "validator": y coordinate can't less than 0
		@Test
		public void testYnotLess0() 
		{
			boolean result;
			int x = 1;
			int y = -2;
			char[][] Ques_arr = new char[9][9];
			char[][] Bd_arr = new char[9][9];
		
			String input = "1";
			char i = 1;
			result = validator.check_input(Ques_arr, Bd_arr, x , y ,input, i,0);
			assertEquals(result, false);
		}
		
		// Test case 6: test class "validator": y coordinate can't larger than 8
		@Test
		public void testYnotLarger8() 
		{
			boolean result;
			int x = 1;
			int y = 9;
			char[][] Ques_arr = new char[9][9];
			char[][] Bd_arr = new char[9][9];
		
			String input = "1";
			char i = 1;
			result = validator.check_input(Ques_arr, Bd_arr, x , y ,input, i,0);
			assertEquals(result, false);
		}
	
		// Test case 7: number n can't less than 1
		@Test
		public void testNnotLess1() {
			boolean result;
			int x = 1;
			int y = 1;
			char[][] Ques_arr = new char[9][9];
			char[][] Bd_arr = new char[9][9];
			String input = "0";
			char i = 0;
			result = validator.check_input(Ques_arr, Bd_arr, x , y ,input, i,0);
			assertEquals(result, false);
		}
		
		// Test case 8: number n can't larger than 9
		@Test
		public void testNnotLarger9() {
			boolean result;
			int x = 1;
			int y = 1;
			char[][] Ques_arr = new char[9][9];
			char[][] Bd_arr = new char[9][9];
			String input = "10";
			char i = 10;
			result = validator.check_input(Ques_arr, Bd_arr, x , y ,input, i,0);
			assertEquals(result, false);
		}
		
		// Test case 9: normal case:number can add in empty position
		// assume Quess_arr[1][1]=' ',users input x=1,y=1, input=2
		@Test
		public void testNempty() {
			boolean result;
			int x = 1;
			int y = 1;
			String input = "2";
			char i = '2';
			char[][] Ques_arr = new char[9][9];
			Ques_arr[1][1]=' ';	
			char[][] Bd_arr = new char[9][9];
		
			result = validator.check_input(Ques_arr, Bd_arr, x , y ,input, i,0);
			assertEquals(result, true);
		}
		
		// Test case 10: test class "validator": Players enter an input of invalid length  in the game.
		@Test
		public void testinvalid_length() 
		{
			boolean result;
			result=validator.is_invalid_length("a");
			assertEquals(result, false);
		}
		
		// Test case 11: test class "validator": Players enter an input of invalid range in the game.
		@Test
		public void testinvalid_range() 
		{
			boolean result;
			result=validator.is_invalid_range("7");
			assertEquals(result, false);
		}
		// Test case 12: test class "validator": Players enter an zero position in the game.
		@Test
		public void testcontain_nonzero_position() 
		{
			boolean result;
			result=validator.contain_nonzero_position(0,0);
			assertEquals(result, false);
		}
		
		// Test case 13: test class "validator": Players enter an invalid value in the game.
		@Test
		public void testis_invalid_value() 
		{
			boolean result;
			result=validator.is_invalid_value("8");
			assertEquals(result, false);
		}
		
			
}
